package com.myjob.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 使用seata对数据源进行代理
 * @author Chen Yuan
 * @create 2021-01-29  10:05
 */
@Configuration
public class DataSourceProxyConfig {

	// mybatis的mapper文件夹地址
	@Value("${mybatis.mapper-locations}")
	private String mapperLocations;

	@Bean
	@ConfigurationProperties(prefix = "spring.datasource.druid")
	public DataSource druidDataSource() {
		DruidDataSource druidDataSource = new DruidDataSource();
		return druidDataSource;
	}
	//
	//@Bean
	//public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
	//	SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
	//	factoryBean.setDataSource(dataSource);
	//	factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
	//			.getResources(mapperLocations));
	//	return factoryBean.getObject();
	//}
}